package com.mzw.huaxiarealestatebackend.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mzw.huaxiarealestatebackend.common.utils.DateFormat;
import com.mzw.huaxiarealestatebackend.entity.BackPage;
import com.mzw.huaxiarealestatebackend.entity.Client;
import com.mzw.huaxiarealestatebackend.entity.Mail;
import com.mzw.huaxiarealestatebackend.dao.MailDao;
import com.mzw.huaxiarealestatebackend.service.MailService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (Mail)表服务实现类
 *
 * @author makejava
 * @since 2023-12-22 17:10:12
 */
@Service("mailService")
public class MailServiceImpl implements MailService {
    @Resource
    private MailDao mailDao;

    /**
     * 发送邮件
     * @param sendNo
     * @param acceptNo
     * @param info
     * @return
     */
    @Override
    public boolean sendMail(String sendNo, String acceptNo, String info,String sendName) {
        Mail mail = new Mail();
        mail.setSendNo(sendNo);
        mail.setAcceptNo(acceptNo);
        mail.setSendName(sendName);

        mail.setSendTime(DateFormat.getNowDateFormat());
        mail.setInfo(info);
        boolean insert = this.insert(mail);
        return insert;
    }

    /**
     * 通过AcceptID查询数据
     *
     * @param acceptNo 主键
     * @return 实例对象
     */
    @Override
    public List<Mail> queryAllByAcceptId(String acceptNo) {
        QueryWrapper<Mail> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("accept_no", acceptNo);
        List<Mail> mails = mailDao.selectList(queryWrapper);
        return mails;
    }


    /**
     * 新增数据
     *
     * @param mail 实例对象
     * @return 实例对象
     */
    @Override
    public boolean insert(Mail mail) {
        int insert = this.mailDao.insert(mail);
        return insert > 0;
    }

    /**
     * 修改数据
     *
     * @param mail 实例对象
     * @return 实例对象
     */
    @Override
    public boolean updateStatus(Mail mail) {
        int update = this.mailDao.updateStatus(mail);
        return update > 0;
    }

    /**
     * 通过主键删除数据
     *
     * @param mailNo 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String mailNo) {
        return this.mailDao.deleteById(mailNo) > 0;
    }
}
